﻿using UnityEngine;
using System.Collections;

public class wire : MonoBehaviour {
	
	
	bool staying;
	 
	bool startPush; 

	float timer; 
	float timerSpawn; 
	float maxTime;


	int count;

	bool spawn;

	// Use this for initialization
	void Start () {

		spawn = true;

	}
	
	// Update is called once per frame
	void Update () {
		
		if(staying && spawn)
		{
			if(Input.GetButtonDown("Submit"))
			{
				Debug.Log("RepitoBoton");
				if(!startPush) startPush = true;

				count++;
			}
			if(startPush)
			{
				if(timer > 2)
				{
					Debug.Log("ResetBoton");
					timer = 0;
					startPush = false;
				}
				else timer += Time.deltaTime;
			}

			if(count > 10)
			{	
				Debug.Log("Logro");

				timer = 0;
				startPush = false;
				count = 0;
				spawn = false;
				maxTime = Random.Range (10,20);

			}
		}
		if(!spawn)
		{
			timerSpawn += Time.deltaTime;
			if(timerSpawn > maxTime) spawn = true;

		}
		
	}
	
	
	void OnTriggerStay(Collider obj)
	{
		if(obj.CompareTag("Player1"))
		{
			staying = true;
		}
	}
	
	void OnTriggerExit(Collider obj)
	{
		if(obj.CompareTag("Player1"))
		{
			staying = false;
			count = 0;
			timer = 0;
			startPush = false;

		}
	}
}
